
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyemsg_printf = binder_py('mx_eyemsg_printf')
eyemsg_printf.mx_c.headers = ['<eyelink.h>','"mex.h"']
eyemsg_printf.bindo += []
eyemsg_printf.mx_c.code = \
"""
INT16 _main( char FARTYPE *msg )
{
    return eyemsg_printf( msg );
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    char FARTYPE *msg;

    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
           
    if (!mxIsChar(prhs[0]))
        mexErrMsgTxt("msg should be a string.");
   
    msg = mxArrayToString(prhs[0]);
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    
    *status = (double ) _main( msg );

    mxFree(msg);

    return;
}
"""

eyemsg_printf.mx_c.mdoc = \
"""function [ ] = mx_eyemsg_printf( )
%MX_EYEMSG_PRINTF This sends a text message to the EyeLink tracker, which 
% timestamps it and writes it to the EDF data file. Messages are useful for
% recording trial conditions, subject responses, or the time of importanti
% events.
% This function is used with the same formatting methods as printf(), allowing
% numbers to be included. Avoid end-of-line characters ("\n") at end of
% messages.
%
% Parameters:
% fmt 	Similar to printf(), format string plus arguments.
% Returns:
% 0 if successfully sent to tracker, else error code.
%
"""
eyemsg_printf.write_c()
eyemsg_printf.write_m()
eyemsg_printf.compile()
eyemsg_printf.write_sh()

